async function getScore() {
    const res = await axios({
        url: '/score/list'
    })
    // Toast.success(res.message)
    document.querySelector('tbody').innerHTML = Object.keys(res.data).map(k => {
        return `<tr>
        <th scope="row">${k}</th>
        <td>${res.data[k].name}</td>
        ${res.data[k].score.map((item, index) => `<td class="score" data-id="${k}"  data-batch="${index + 1}">${item}</td>`).join('')}
      </tr>`
    }).join('')
}
getScore()

let inp = document.createElement('input')
document.querySelector('tbody').addEventListener('click', async e => {
    if (e.target.classList.contains('score')) {
        inp.classList.add('inp')
        inp.value = e.target.innerHTML
        e.target.append(inp)
        inp.focus()
    }
})
inp.addEventListener('keydown', async e => {
    if (e.key === 'Enter') {
        const stu_id = e.target.parentNode.dataset.id
        const batch = e.target.parentNode.dataset.batch
        const score = inp.value
        try {
            const res = await axios({
                url: '/score/entry',
                method: 'POST',
                data: { stu_id, batch, score }
            })
            Toast.success(res.message)
        } catch (error) {
            Toast.fail('只能输入0-100数字')
        }
        getScore()
    }
})